<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" :form="form" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">          
          <a-col :md="6" :sm="8">
            <a-form-item label="展会主题">
              <a-select v-model="exhibitionMeetingId">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option v-for="(item, index) in dictOptiond" :key="index" :value="item.id">
                  <span style="display: inline-block;width: 100%">
                    {{ item.theme }}
                  </span>
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" v-if="dataSource.length>0" icon="download" @click="handleExportXls('二维码')">下载二维码</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <div v-else @click="jumpProview(text)">
            <img                     
              :src="getImgView(text)"
              height="25px"
              alt="图片不存在"
              style="max-width:80px;font-size: 12px;font-style: italic;"            
            />
          </div>
        </template>
        <template slot="typeSlot" slot-scope="text,record">
          <span v-if="record.locationType == 0">{{record.hotelNumber}}</span>
          <span v-if="record.locationType == 1">{{record.lineNumber+record.columnNumber}}</span>
        </template>
        <span slot="lineSlot" slot-scope="text, record">
            {{record.lineNumber+record.columnNumber}}
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <JProviewImg v-if="showImg" @closeProview="closeProview" :imgurl="proviewUrl"></JProviewImg>
    <!-- <exhibition_tickets-modal ref="modalForm" @ok="modalFormOk"></exhibition_tickets-modal> -->
  </a-card>
</template>

<script>
  import Exhibition_ticketsModal from './modules/Exhibition_ticketsModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JProviewImg from '@/components/jeecg/JProviewImg.vue'
  import { validateDuplicateValue } from '@/utils/util'
  import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
  import { getAction,downFile } from '@/api/manage'

  export default {
    name: "Exhibition_ticketsList",
    mixins:[JeecgListMixin],
    components: {
      Exhibition_ticketsModal,
      JProviewImg
    },
    data () {
      return {
        exhibitionMeetingId:"",
        distributorId:"",
        queryParamphone:"",
        form: this.$form.createForm(this),
        description: '展会门票管理管理页面',
        dictOption:[],
        dictOptiond:[],
        showImg:false,
        proviewUrl:"",
        userAuth2btn:"1",
        ipagination: {
          current: 1,
          pageSize: 10,
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            dataSource:[],
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
           {
              title: '展会主题',
              align: 'center',
              dataIndex: 'theme'
            },
           {
            title: '房间号',
            align:"center",
            dataIndex: 'hotelNumber',
            scopedSlots: { customRender: 'typeSlot' }
           },
		      {
            title: '二维码',
            align:"center",
            dataIndex: 'tickets',
            scopedSlots: { customRender: 'imgSlot' }
           },
          //  {
          //   title: '座位号',
          //   align:"center",
          //   dataIndex: 'lineNumber',
          //   scopedSlots: { customRender: 'lineSlot' }
          //  },
          //  {
          //   title: '验证码',
          //   align:"center",
          //   dataIndex: 'captcha'
          //  },
		      // {
          //   title: '票具主次类型',
          //   align:"center",
          //   dataIndex: 'ticketsType',
          //   customRender: text => {
          //     return filterMultiDictText(this.dictOptions['ticketsType'], text + '')
          //   }
          //  },
		      // {
          //   title: '短信状态',
          //   align:"center",
          //   dataIndex: 'smsStatus',
          //   customRender: text => {
          //     return filterMultiDictText(this.dictOptions['smsStatus'], text + '')
          //   }
          //  },
		      // {
          //   title: '是否被绑定',
          //   align:"center",
          //   dataIndex: 'bindStatus',
          //   customRender: text => {
          //     return filterMultiDictText(this.dictOptions['ticketsStatus'], text + '')
          //   }
          //  },     
          // {
          //   title: '发行方名称',
          //   align:"center",
          //   dataIndex: 'issuerName'
          //  },
          //  {
          //   title: '店家手机号',
          //   align:"center",
          //   dataIndex: 'phonenumber'
          //  },         
		      // {
          //   title: '分销商',
          //   align:"center",
          //   dataIndex: 'name'
          //  },
          //  {
          //   title: '分销商手机号',
          //   align:"center",
          //   dataIndex: 'phone'
          //  }
        ],
		url: {
          list: "/exhibition/exhibition_tickets/list",
          delete: "/exhibition/exhibition_tickets/delete",
          deleteBatch: "/exhibition/exhibition_tickets/deleteBatch",
          exportXlsUrl: "exhibition/exhibition_tickets/exportXls",
          importExcelUrl: "exhibition/exhibition_tickets/importExcel",
       },
       dictOptions: {
        ticketsType: [],
        ticketsStatus: [],
        smsStatus:[]
      },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  mounted (){   
    getAction("/block/blockManufacturerInfo/userAuth2btn")
        .then(res => {
          if (res.success) {
            this.userAuth2btn = res.result.status;
          } else {
            that.$message.warning(res.message)
          }
        })  
      var paramd={
        column:"createTime",
        order:"desc",
        field:"id,,,name,phone,remark,action",
        pageNo:1,
        pageSize: 1000
      };
      getAction("/exhibition/exhibition_distributor_info/list",paramd).then((res) => {
        if (res.success) {
          this.dictOption = res.result.records;
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
      })
      var params={
        column:"createTime",
        order:"desc",
        field:"id,,,name,phone,remark,action",
        pageNo:1,
        pageSize: 1000
      };
      getAction("/exhibition/exhibition_meeting_info/list",params).then((res) => {
        if (res.success) {
          this.dictOptiond = res.result.records;
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
      })
    },
  methods: {
    handleExportXls(fileName){
      if(!this.exhibitionMeetingId){
      this.$message.warning("请选择展会主题！")
        return
      }        
      let param = {
        "exhibition_meeting_id":this.exhibitionMeetingId
      }
      downFile("/exhibition/exhibition_tickets/downloadTickets",param).then((data)=>{
        if (!data) {
          this.$message.warning("文件下载失败")
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data]), fileName+'.zip')
        }else{
          let url = window.URL.createObjectURL(new Blob([data]))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName+'.zip')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link); //下载完成移除元素
          window.URL.revokeObjectURL(url); //释放掉blob对象
        }
      })
      // getAction("/exhibition/exhibition_tickets/downloadTickets",param).then((res) => {
      //   if (res.success) {
      //     if(res.result){
      //     }else{
      //       this.$message.warning(res.message)
      //     }
      //   }
      //   if(res.code===510){
      //     this.$message.warning(res.message)
      //   }
      // })
    },
    modalFormOk() {
      var paramd={
        exhibitionMeetingId:this.exhibitionMeetingId,
        // distributorId:this.distributorId,
        column:"createTime",
        order:"desc",
        field:"id,,,name,phone,remark,action",
        pageNo:1,
        pageSize: 10
      };
      getAction("/exhibition/exhibition_tickets/list",paramd).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
      })
    },
    searchReset(){
      this.exhibitionMeetingId = "";
      // this.distributorId = "";
      var paramd={
        column:"createTime",
        order:"desc",
        field:"id,,,name,phone,remark,action",
        pageNo:1,
        pageSize: 10
      };
      getAction("/exhibition/exhibition_tickets/list",paramd).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
      })
    },
    handleTableChange(pagination, filters, sorter) {
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc';
      }
      this.ipagination = pagination;
      var paramd={
        exhibitionMeetingId:this.exhibitionMeetingId,
        // distributorId:this.distributorId,
        column:"createTime",
        order:"desc",
        field:"id,,,name,phone,remark,action",
        pageNo:this.ipagination.current,
        pageSize: 10
      };
      getAction("/exhibition/exhibition_tickets/list",paramd).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
      })
    },
    searchQuery(){
      this.ipagination.current = 1;
      var paramd={
        // distributorId:this.distributorId,
        exhibitionMeetingId:this.exhibitionMeetingId,
        column:"createTime",
        order:"desc",
        field:"id,,,name,phone,remark,action",
        pageNo:1,
        pageSize: 10
      };
      getAction("/exhibition/exhibition_tickets/list",paramd).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
      })
    },
    closeProview(){
      this.showImg = false;
    },
    jumpProview(val){
      this.showImg = true;
      this.proviewUrl = val;
    },
    initDictConfig() {
      initDictOptions('tickets_type').then(res => {
        if (res.success) {
          this.$set(this.dictOptions, 'ticketsType', res.result)
        }
      })
      initDictOptions('tickets_status').then(res => {
        if (res.success) {
          this.$set(this.dictOptions, 'ticketsStatus', res.result)
        }
      })
      initDictOptions('sms_status').then(res => {
        if (res.success) {
          this.$set(this.dictOptions, 'smsStatus', res.result)
        }
      })
    },
  }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>